package com.gugee.ins.common.dal.mapper.statistics;

import com.gugee.common.mapper.GugeeMapper;
import com.gugee.ins.common.model.es.StatisticsData;
import com.gugee.ins.common.model.mysql.statistics.InsStBloggerNation;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface InsStBloggerNationMapper extends GugeeMapper<InsStBloggerNation> {

    @Delete("delete from ins_st_blogger_nation where uid = #{uid}")
    void deleteByUid(long uid);


    @Select("SELECT b.nation nation,count(*) nationRate " +
            "FROM ins_rel_blogger_active_follower ba LEFT JOIN ins_blogger b ON ba.f_uid = b.uid " +
            "WHERE ba.uid = #{uid} and b.nation is not null GROUP BY  b.nation ORDER BY nationRate DESC limit 0,#{size} ")
    List<InsStBloggerNation> findByActiveFollower(long uid, int size);

    @Select("select * from ins_st_blogger_nation WHERE uid = #{uid} ORDER BY nation_rank ")
    List<InsStBloggerNation> findByUid(long uid);

    @Select("select nation `property`,nation_rank `rank`,nation_rate `value` from ins_st_blogger_nation WHERE uid = #{uid} ORDER BY nation_rank ")
    List<StatisticsData> findStatisticsDataByUid(long uid);
}